package main

import "math"

func main() {
	println(findNthDigit(13))
}

func findNthDigit(n int) int {
	if n < 10 {
		return n
	}

	for i, j, num := 2, 10, 9; i < 10; i++ {
		if n > num+j*9*i {
			num += j * 9 * i
			j *= 10
			continue
		}
		digitIndex := (n - num) % i
		num = int(math.Pow10(i-1)) + (n-num)/i
		if digitIndex == 0 {
			return (num - 1) % 10
		}
		return num / int(math.Pow10(i-digitIndex)) % 10
	}
	return n
}
